<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="5" :sm="8">
            <a-form-item label="接口路径">
              <a-input placeholder="请输入接口路径" v-model="queryParam.interfaceUrl" @pressEnter="searchQuery"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="8">
            <a-form-item label="名称">
              <a-input placeholder="请输入名称" v-model="queryParam.name" @pressEnter="searchQuery"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="8">
            <span style="float: left;overflow: hidden;margin-top: 5px;" class="table-page-search-submitButtons">
              <a-button type="primary" size="small" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" size="small" @click="searchReset" icon="reload"
                        style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" size="small" icon="plus" v-has="'DataRuleList:add'">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('数据规则')" v-has="'DataRuleList:exportXls'">导出
      </a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
                @change="handleImportExcel">
        <a-button type="primary" icon="import" v-has="'DataRuleList:importXls'">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0" v-has="'DataRuleList:deleteBatch'">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">
        <div slot="filterDropdown">
          <a-card>
            <a-checkbox-group @change="onColSettingsChange"  v-model="settingColumns"  :defaultValue="settingColumns">
              <a-row>
                <template v-for="item in defColumns">
                  <template v-if="item.key != 'rowIndex' && item.dataIndex != 'action'">
                    <a-col :span="6"  :key="item.key">
                      <a-checkbox :value="item.dataIndex">
                        {{ item.title }}
                      </a-checkbox>
                    </a-col>
                  </template>
                </template>
              </a-row>
            </a-checkbox-group>
          </a-card>
        </div>

        <a-icon slot="filterIcon"  type="setting"  :style="{ fontSize: '16px', color: '#fff' }"  />
        <template slot="interfaceUrl" slot-scope="text,record">
          <j-ellipsis v-if="text" :value="text" :length="30"></j-ellipsis>
          <j-ellipsis v-else :value="record.interfaceUrl" :length="30"></j-ellipsis>
        </template>
        <template slot="conditionResultsText" slot-scope="text,record">
          <j-ellipsis v-if="text" :value="text" :length="15"></j-ellipsis>
          <j-ellipsis v-else :value="record.conditionResults" :length="15"></j-ellipsis>
        </template>
        <template slot="dataJudgeResultsText" slot-scope="text,record">
          <j-ellipsis v-if="text" :value="text" :length="15"></j-ellipsis>
          <j-ellipsis v-else :value="record.dataJudgeResults" :length="15"></j-ellipsis>
        </template>
        <template slot="conditionCategory" slot-scope="text,record">
          <span v-if="text==='currentDepart'">当前部门</span>
          <span v-if="text==='currentRole'">当前角色</span>
          <span v-if="text==='currentUser'">当前用户</span>
        </template>
        <template slot="dataJudgeCategory" slot-scope="text,record">
          <span v-if="text==='currentUserId'">当前用户主键</span>
          <span v-if="text==='depart'">部门</span>
          <span v-if="text==='sql'">sql语句</span>
          <span v-if="text==='user'">用户</span>
        </template>
        <template slot="status" slot-scope="text">
          <a-tag v-if="text==0" color="red">停止</a-tag>
          <a-tag v-if="text==1" color="blue">启用</a-tag>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'DataRuleList:edit'">编辑</a>

          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)" v-has="'DataRuleList:delete'">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <dataRule-modal ref="modalForm" @ok="modalFormOk"></dataRule-modal>
  </a-card>
</template>

<script>

  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import DataRuleModal from './modules/DataRuleModal'
  import JEllipsis from '@/components/jeecg/JEllipsis';

  export default {
    name: "DataRuleList",
    mixins: [JeecgListMixin],
    components: {
      JEllipsis,
      DataRuleModal
    },
    data() {
      return {
        description: '数据规则管理页面',
        // 表头
        settingColumns: [],
        columns: [],
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '接口路径',
            align: "center",
            dataIndex: 'interfaceUrl',
            scopedSlots:{customRender:'interfaceUrl'}
          },
          {
            title: '名称',
            align: "center",
            dataIndex: 'name'
          },
          {
            title: '条件类别',
            align: "center",
            dataIndex: 'conditionCategory',
            scopedSlots:{customRender:'conditionCategory'}
          },
          {
            title: '条件',
            align: "center",
            dataIndex: 'conditions'
          },
          {
            title: '条件结果',
            align: "center",
            dataIndex: 'conditionResultsText',
            scopedSlots:{customRender:'conditionResultsText'}
          },
          {
            title: '优先级',
            align: "center",
            dataIndex: 'priority'
          },
          {
            title: '表名',
            align: "center",
            dataIndex: 'tableName'
          },
          {
            title: '表描述',
            align: "center",
            dataIndex: 'tableDescription'
          },
          {
            title: '字段名',
            align: "center",
            dataIndex: 'fieldName'
          },
          {
            title: '字段描述',
            align: "center",
            dataIndex: 'fieldDescription'
          },
          {
            title: '数据判断类别',
            align: "center",
            dataIndex: 'dataJudgeCategory',
            scopedSlots:{customRender:'dataJudgeCategory'}
          },
          {
            title: '数据判断结果',
            align: "center",
            dataIndex: 'dataJudgeResultsText',
            scopedSlots:{customRender:'dataJudgeResultsText'}
          },
          {
            title: '状态',
            align: "center",
            dataIndex: 'status',
            scopedSlots:{customRender:'status'}
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: {
              filterDropdown: 'filterDropdown', // 新增筛选插槽
              filterIcon: 'filterIcon', // 新增图标插槽
              customRender: 'action' // 原操作列插槽
            }
          }
        ],
        url: {
          list: "/datarule/dataRule/list",
          delete: "/datarule/dataRule/delete",
          deleteBatch: "/datarule/dataRule/deleteBatch",
          exportXlsUrl: "/datarule/dataRule/exportXls",
          importExcelUrl: "datarule/dataRule/importExcel"
        },
        dictOptions: {}

      }
    },
    computed: {
      importExcelUrl: function () {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig() {
      }

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>